package com.monster.starter.security.service.impl;

import com.monster.json.JsonUtils;
import com.monster.starter.security.common.SecurityConfig;
import com.monster.starter.security.service.abs.TransmissionCipherAbstractService;
import com.monster.utils.IdUtils;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

/**
 * 安全的service类实现类
 * 本地存储配置（单节点）
 * 只有配置的type为local的时候才实例化这个
 *
 * @author kuang
 */
@Slf4j
@Service
@ConditionalOnProperty(prefix = "monster.security", name = "type", havingValue = "local", matchIfMissing = true)
public class TransmissionCipherLocalServiceImpl extends TransmissionCipherAbstractService {
    /**
     * 安全的一些配置
     */
    @Autowired
    private SecurityConfig config;
    /**
     * 每个小时30分钟的时候生产下一个小时的工具吗
     */
    @PostConstruct
    @Scheduled(cron = "${monster.security.cipherCorn}")
    public void add () {
        String key = IdUtils.getUUID();
        available.put(key, createRsaInfo(key));
        log.info("生成当前时间密钥：{}", JsonUtils.toFormatJson(available.get(key)));
    }
}
